#ifndef SPECTRUMANALYZER_H
#define SPECTRUMANALYZER_H

#include <QObject>
#include <QVector>
#include <complex>
#include <cmath>




class SpectrumAnalyzer : public QObject
{
    Q_OBJECT

public:
    explicit SpectrumAnalyzer(int numBands = 20, QObject *parent = nullptr);

    void processAudioData(const QVector<float> &audioData, int sampleRate);
    QVector<float> getSpectrum() const { return m_spectrum; }
    int getNumBands() const { return m_numBands; }

signals:
    void spectrumReady(const QVector<float> &spectrum);

private:
    void performFFT(const QVector<float> &input, QVector<std::complex<float>> &output);
    void calculateSpectrum(const QVector<std::complex<float>> &fftData, int sampleRate);
    QVector<float> applyHannWindow(const QVector<float> &input);

    int m_numBands;
    int m_fftSize;
    QVector<float> m_spectrum;
};

#endif // SPECTRUMANALYZER_H